#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <qtimer.h>
#include "TCPIPRobot.hpp"
#include "optoforce_data.h"

#define RightGraspControl 8
#define LeftGraspControl 14
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:
    void force_data_loop_run();

private slots:
    void on_btn_GraspOpen_clicked();

    void on_btn_GraspClose_clicked();

    void on_btn_data_start_clicked();

    void on_btn_data_stop_clicked();

    void on_btn_GraspConnect_clicked();

    void on_force_range_valueChanged(int arg1);

    void on_torque_range_valueChanged(int arg1);

private:
    Ui::MainWindow *ui;
    int force_range = 50;
    int torque_range = 10;

    QTimer *force_data_loop;

    TCPIPRobot *_tcpipGrasp=nullptr;
    TCPIPRobot *_tcpipLeftGrasp=nullptr;
    int isGraspConnect = -1;

    optoforce_data * force_data_receiver = nullptr;
    bool is_data_receiving = false;
    double force_data[6] = {0, 0, 0, 0, 0, 0};

    //grasp control
    const unsigned char buffGraspInit[RightGraspControl] = {0x01, 0x06, 0x01, 0x00, 0x00, 0xA5, 0x48, 0x4D};
    const unsigned char buffGraspOpen[RightGraspControl] = {0x01, 0x06, 0x01, 0x03, 0x00, 0x96, 0xF8, 0x58};
    const unsigned char buffGraspClose[RightGraspControl] = {0x01, 0x06, 0x01, 0x03, 0x00, 0x32, 0xF9, 0xE3};

    //left grasp control
    const unsigned char buffLeftGraspInit[LeftGraspControl] = {0xFF, 0xFE, 0xFD, 0xFC, 0x01, 0x08, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFB};//init
    const unsigned char buffLeftGraspOpen[LeftGraspControl] = {0xFF, 0xFE, 0xFD, 0xFC, 0x01, 0x06, 0x02, 0x01, 0x00, 0x64, 0x00, 0x00, 0x00, 0xFB};
    const unsigned char buffLeftGraspClose[LeftGraspControl] = {0xFF, 0xFE, 0xFD, 0xFC, 0x01, 0x06, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFB};
};

#endif // MAINWINDOW_H
